package ink.sunflowerk.pojo;

import java.util.List;

/**
 * 定义一个分页对象
 *
 * @author acer
 */
public class PagerBean<T> {
    //总记录数
    private int totalCount;
    //总页码=总记录数 % 每页显示条数 == 0 ？ 总记录数/每页显示条数 ： 总记录数/每页显示条数+1;
    private int totalPage;
    private List<T> list; //每页的数据 list集合
    private int currentPage; //当前页码
    private int pageRows;// 每页显示的条数
//    private String hql;//分页语句

    public static void main(String[] args) {
        PagerBean<String> bean = new PagerBean<>();
        bean.setRows(3);
        bean.setTotalCount(10);
        bean.setCurrentPage(2);
        System.out.println("起始页"+bean.getStartRow());
        System.out.println("当前页"+bean.getCurrentPage());
        System.out.println("总页码"+bean.getTotalPage());
    }

    public PagerBean() {
    }

    public int getStartRow() {
        return (currentPage - 1) * pageRows;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
        totalPage = totalCount % pageRows == 0 ? (totalCount / pageRows) : (totalCount / pageRows + 1);
    }

    public int getTotalPage() {
        return totalPage;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getRows() {
        return pageRows;
    }

    public void setRows(int pageRows) {
        this.pageRows = pageRows;
    }

    @Override
    public String toString() {
        return "PagerBean{" +
                "totalCount=" + totalCount +
                ", totalPage=" + totalPage +
                ", list=" + list +
                ", currentPage=" + currentPage +
                ", pageRows=" + pageRows +
                '}';
    }
//    public String getHql() {
//        return hql;
//    }

//    public void setHql(String hql) {
//        this.hql = hql;
//    }
}